<?php
/**
 * 网站的统一入口
 * @var action
 */
//定义一些常量
define('DOMAIN','http://local.cms.com/my_cms/web/');
define('IMG_DOMAIN','http://img.1mobile.com/');

// APP_ROOT必须定义,并且必须定义为APP_ROOT
define ('APP_ROOT', dirname (__FILE__));
//加载mvc框架
require_once (APP_ROOT.'/../mvc/mymvc.php');

define('CACHE_PATH',APP_ROOT.'/cache/');
define('CONTROL_PATH',APP_ROOT.'/control/');
define('MODEL_PATH',APP_ROOT.'/model/');

//定义smarty的路径
define('TEMPLATE_DIR',APP_ROOT.'/view/');
define('COMPILE_DIR',APP_ROOT.'/view_c/');

//加载项目的配置文件
C(require_once(APP_ROOT.'/config/config.php'));

//加载基类
require_once(CONTROL_PATH.'BaseControl.class.php');

//传递过来的参数是xxx.xxx形式，如果没有.,控制器直接调用Index
$c = trim($_REQUEST["c"]);
if(empty($c)){
	$action = 'index';
}elseif(strpos($c,'.') === false){
	$action = $c;
}else{
	list($controller,$action) = explode('.',$c);
	$controller = ucfirst(strtolower($controller));
}
$controller=(!empty($controller))?$controller:'Index';//获取控制器,默认index
$controller_name=$controller.'Control';
$controller_file=APP_ROOT.'/control/'.$controller_name.'.class.php';//获取控制器文件

if(file_exists($controller_file)){
	require_once($controller_file);
	$controller=new $controller_name();
	if(method_exists($controller,$action.'Action')){
		$controller->{$action.'Action'}();
	}else{
		redirect(DOMAIN);
	}
}else{
	redirect(DOMAIN);
}